<style lang="scss">
.picker-image {
  &-hd {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    .btn-actions {
      display: flex;
    }
    .btn-upload {
      margin-right: 10px;
    }
  }
  &-bd {
    display: flex;
    padding: 0 0 10px 10px;
    .lf-container {
      width: 220px;
      background: #f5f5f5;
      height: 530px;
      margin-right: 8px;
      padding: 8px;
      overflow: auto;
      .el-tree{
        overflow-x: auto;
        height: 100%;
        .el-tree-node>.el-tree-node__children{
          overflow: unset;
        }
      }
      .icon-edit {
        font-size: 13px;
        float: right;
        display: none;
      }
      // .icon-trash-alt1 {
      //   font-size: 13px;
      //   float: right;
      //   margin-top: 1px;
      //   margin-right: 6px;
      //   display: none;
      // }
    }
    .rg-container {
      flex: 1;
    }
  }
  .catgory-item {
    height: 30px;
    line-height: 30px;
    padding: 0 6px;
    &:hover {
      color: rgb(255, 255, 255);
      background-color: rgba(0, 0, 0, 0.4);
      .icon-edit {
        display: block;
      }
      // .icon-trash-alt1 {
      //   display: block;
      // }
    }
    &.active {
      color: rgb(255, 255, 255);
      background-color: var(--themeColor);
    }
  }
  .image-item {
    &-wrap {
      display: inline-block;
      position: relative;
      margin-right: 8px;
      margin-bottom: 8px;
      font-size: 14px;
      vertical-align: middle;
      cursor: pointer;
    }
    display: flex;
    align-items: flex-end;
    width: 120px;
    height: 120px;
    box-sizing: border-box;
    background: 50% 50% / cover no-repeat rgb(221, 221, 221);
    &:hover {
      .image-meta {
        display: block;
      }
      .icon-link {
        display: block;
      }
      .icon-preview {
        display: block;
      }
      .icon-trash-alt1 {
        display: block;
      }
    }
    .image-meta {
      height: 28px;
      width: 100%;
      line-height: 28px;
      text-align: center;
      color: rgb(255, 255, 255);
      background-color: rgba(0, 0, 0, 0.4);
      display: none;
    }
    .icon-link {
      position: absolute;
      top: 2px;
      left: 4px;
      display: none;
      color: #666;
    }
    .icon-preview{
      position: absolute;
      top: 30px;
      left: 4px;
      font-weight: bold;
      font-size: 17px;
      display: none;
      color: #666;
    }
    .icon-trash-alt1 {
      position: absolute;
      bottom: 22px;
      left: 4px;
      display: none;
      color: #666;
    }
  }
  .image-title-wrap {
    width: 120px;
    &__title {
      font-size: 12px;
      @include text-overflow();
    }
  }
  .el-pagination {
    margin-top: 8px;
    text-align: right;
  }
  .image-box-selected {
    position: absolute;
    box-sizing: border-box;
    top: 0;
    left: 0;
    width: 120px;
    height: 120px;
    border: 2px solid var(--themeColor);
    color: #fff;
    overflow: hidden;
    pointer-events: none;
    &__right-angle {
      position: absolute;
      top: -21px;
      right: -21px;
      width: 42px;
      height: 42px;
      -webkit-transform: rotate(45deg);
      transform: rotate(45deg);
      background: var(--themeColor);
    }
    &__text {
      position: absolute;
      top: -2px;
      right: 3px;
    }
    .icon-check {
      position: relative;
      top: -2px;
      right: -2px;
    }
  }
  .image-list {
    height: 452px;
  }
  .cropper-container {
    width: 498px;
    height: 498px;
    position: relative;
    .cropper-actions {
      position: absolute;
      bottom: 0;
      left: 10px;
      .iconfont {
        font-size: 18px;
        color: #fff;
        margin-right: 6px;
      }
      .icon-search-minus,
      .icon-search-plus {
        font-size: 19px;
      }
    }
  }
}
.custom-tree-node {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  padding-right: 8px;
  .op-btns-box{
    margin-left: 10px;
    opacity: 0;
    // transition: all 0.5s ease;
  }
  &:hover{
    .op-btns-box{
      opacity: 1;
    }
  }
}
.mR5{
  margin-right: 5px;
}
.searchBox{
  margin-bottom: 5px;
  margin-right: 10px;
}
</style>
<template>
  <div class="picker-image">
    <div class="picker-image-hd">
      <div class="btn-actions">
        <el-upload
          class="btn-upload"
          action=""
          accept="image/jpeg,image/png,image/gif"
          :multiple="true"
          :show-file-list="false"
          :data="localpostData"
          :http-request="handleUpload"
          :before-upload="beforeAvatarUpload"
          :on-success="handleAvatarSuccess"
          :on-error="uploadError"
        >
          <el-button>上传图片</el-button>
        </el-upload>
        <el-button @click="onAddGroup"> 添加分组 </el-button>
        <el-button :disabled="disabledBtn" @click="onMoveGroup"> 移组 </el-button>
        <!-- <el-button :disabled="disabledDeleteGroup" @click="onDeleteImageGroup">
          删除分组
        </el-button> -->
        <!-- <el-button :disabled="disabledBtnEdit" @click="handleEdit"> 编辑 </el-button> -->
        <!-- <el-button
          :disabled="disabledBtnCropper"
          @click="handleCropper"
        >
          裁剪
        </el-button> -->

        <!-- <el-button
          :disabled="disabledBtnDelete"
          @click="handleEdit"
        >
          删除
        </el-button> -->
        <!-- <el-button
          :disabled="disabledBtnDownload"
          @click="handleEdit"
        >
          下载
        </el-button> -->
        <el-button :disabled="disabledBtn" @click="handleCancelAll"> 全部取消 </el-button>
      </div>
      <!-- <div>
        <el-input size="small" placeholder="请输入图片名称" suffix-icon="el-icon-search" />
      </div> -->
    </div>
    <div class="picker-image-bd">
      <div class="lf-container">
        <el-tree
          ref="treeRef"
          :props="{
            label:'image_cat_name',
            isLeaf:'image_cat_name',
          }"
          :data="catgoryList"
          node-key="image_cat_id"
          :expand-on-click-node="false"
          @node-click="handleClickCatgory"
          :load="loadNode"
          lazy
          render-after-expand
          highlight-current
          :default-expanded-keys="[0]"
          :current-node-key="0"
        >
          <span class="custom-tree-node" slot-scope="{ node, data }">
            <span>{{ data.image_cat_name }}</span>
            <span class="op-btns-box">
              <!-- <i v-if="data.image_cat_id != 0" class="el-icon-plus mR5" @click.stop="onAddChild(data)"></i> -->
              <i v-if="data.image_cat_id != 0" class="el-icon-edit mR5" @click.stop="onEditGroup(data,node)"></i>
              <i v-if="data.image_cat_id != 0" class="el-icon-delete" @click.stop="onDeleteGroup(data,node)"></i>
            </span>
          </span>
        </el-tree>
        <!-- <div
          v-for="(item, index) in catgoryList"
          :key="`catgory-item__${index}`"
          class="catgory-item"
          :class="{
            active: selectCatgory == item.image_cat_id
          }"
          @click="handleClickCatgory(item)"
        >
          <i class="iconfont icon-folder1" />
          {{ item.image_cat_name }}
          <i v-if="index > 0" class="iconfont icon-edit" @click.stop="onEditGroup(item)" />
          <i v-if="index > 0" class="iconfont icon-trash-alt1" @click.stop="onDeleteGroup(item)" />
        </div> -->
      </div>
      <div class="rg-container">
        <div class="searchBox">
          <el-input v-model="searchImgName" placeholder="请输入图片名称" @keyup.native.enter="refresh" clearable >
            <el-button slot="append" icon="el-icon-search" @click.stop="refresh"></el-button>
          </el-input>
        </div>
        <div v-loading="loading" class="image-list">
          <div
            v-for="(item, index) in list"
            :key="`image-item-wrap__${index}`"
            class="image-item-wrap"
            @click="handleClickItem(item)"
          >
            <div class="image-item" :style="{ color: '#fff', backgroundImage: `url(${item.url})` }">
              <i class="iconfont icon-link" @click.stop="handleCopy(item.url)" />
              <i v-if="preview" class="iconfont el-icon-zoom-in icon-preview" @click.stop="handlePreview(item)" />
              <i v-if="del" class="iconfont icon-trash-alt1" @click.stop="removeItem(item, index)" />
              <!-- <span class="image-meta">800*800</span> -->
            </div>
            <div class="image-title-wrap" :title="item.image_name">
              <p class="image-title-wrap__title">
                {{ item.image_name }}
              </p>
            </div>
            <div v-if="multiple ? isActive(item) > -1 : isActive(item)" class="image-box-selected">
              <div class="image-box-selected__right-angle" />
              <div class="image-box-selected__text">
                <span v-if="multiple">{{ isActive(item) + 1 }}</span>
                <i v-if="!multiple" class="iconfont icon-check" />
              </div>
            </div>
          </div>
          <el-empty v-if="list.length == 0" description="暂无数据" />
        </div>
        <el-pagination
          layout="total, prev, pager, next"
          :current-page.sync="pageCur"
          :page-size="pageSize"
          :total="pageCount"
          @current-change="goPage"
        />
      </div>
    </div>

    <!-- 添加分组 -->
    <SpDialog
      ref="groupDialogRef"
      v-model="groupDialog"
      title="添加分组"
      :modal="false"
      :form="groupForm"
      :form-list="groupFormList"
      @onSubmit="onGroupFormSubmit"
    />
    <!-- 移动分组 -->
    <el-dialog
      title="移动分组"
      :visible.sync="editDialog"
      :before-close="()=>{this.editDialog = false}"
      append-to-body
      width="800px"
      destroy-on-close
    >
      <template>
        <el-form ref="editForm" label-width="180px" :model="editForm" @submit.native.prevent>
          <el-form-item prop="groupId" label="图片分组" required
            :rules="[
              { required: true,message: '请选择分组'},
            ]"
          >
            <!-- <el-input placeholder="请选择分组" type="text" v-model="editForm.groupId" autofocus="true"></el-input> -->
            <el-cascader v-model="editForm.groupId" :props="cascaderProps" placeholder="请选择分组" clearable></el-cascader>
          </el-form-item>

        </el-form>
      </template>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click.native="editDialog = false">
          取消
        </el-button>
        <el-button
          type="primary"
          @click="onEditFormSubmit"
        >
          提交
        </el-button>
      </div>
    </el-dialog>

    <!-- 编辑 -->
    <!-- <SpDialog
      ref="editDialogRef"
      v-model="editDialog"
      title="移动分组"
      :modal="false"
      :form="editForm"
      :form-list="editFormList"
      @onSubmit="onEditFormSubmit"
    /> -->

    <!-- 图片裁剪 -->
    <el-dialog
      class="cropper-dialog"
      title="图片裁剪"
      :modal="false"
      :visible.sync="cropperDialogShow"
      width="500px"
    >
      <div class="cropper-container">
        <vueCropper
          ref="cropper"
          :img="option.img"
          :output-size="option.size"
          :output-type="option.outputType"
          :auto-crop="option.autoCrop"
        />
        <div class="cropper-actions">
          <i class="iconfont icon-search-minus" @click="handleCropperAction('minus')" />
          <i class="iconfont icon-search-plus" @click="handleCropperAction('plus')" />
          <i class="iconfont icon-undo-alt" @click="handleCropperAction('rotateRight')" />
          <i class="iconfont icon-redo-alt" @click="handleCropperAction('rotateLeft')" />
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cropperDialogShow = false">取 消</el-button>
        <el-button type="primary" @click="cropperDialogShow = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 图片预览 -->
    <el-image
      ref="previewImg"
      style="display: none;"
      :src="previewImg" 
      :preview-src-list="[previewImg]"
    ></el-image>
  </div>
</template>

<script>
import { VueCropper } from 'vue-cropper'
import UploadUtil from '@/utils/uploadUtil'
import { isObject, isArray } from '@/utils'
import BasePicker from './base'
import PageMixin from '../mixins/page'
import { deleteImage } from '@/api/qiniu'
export default {
  name: 'PickerImage',
  components: {
    VueCropper
  },
  extends: BasePicker,
  mixins: [PageMixin],
  config: {
    title: '我的图片'
  },
  props: ['value'],
  data() {
    let { multiple = false, data,del = false,preview = false } = this.value || {}
    if (!data) {
      data = multiple ? [] : ''
    }
    return {
      del,
      multiple,
      preview,
      list: [],
      selected: data,
      catgoryList: [],
      selectCatgory: 0,
      groupDialog: false,
      groupForm: {
        groupId: '',
        groupName: '',
        parent_name:'全部图片',
        parent_id:0,
        sort:0,
      },
      groupFormList: [
        // {
        //   label: '上级id',
        //   key: 'parent_id',
        //   type: 'text',
        // },
        {
          label: '上级分组',
          key: 'parent_name',
          type: 'text',
          maxlength: 20,
        },
        {
          label: '分组名称',
          key: 'groupName',
          type: 'input',
          maxlength: 20,
          placeholder: '请输入分组名称',
          required: true,
          message: '不能为空'
        },
        {
          label: '排序',
          key: 'sort',
          type: 'number',
          maxlength: 20,
          placeholder: '请输入排序',
          required: true,
          message: '不能为空'
        },
      ],
      editDialog: false,
      editForm: {
        groupId: ''
      },
      editFormList: [
        {
          label: '图片分组',
          key: 'groupId',
          placeholder: '请选择图片分组',
          type: 'select',
          options: [],
          required: true,
          message: '不能为空'
        }
      ],
      cropperDialogShow: false,
      localpostData: {
        token: '',
        key: '',
        fname: ''
      },
      option: {
        img: '',
        size: 1,
        autoCrop: true
      },
      cascaderProps: {
        checkStrictly:true,
        lazy: true,
        lazyLoad:this.loadNode,
        value:'image_cat_id',
        label:'image_cat_name',
        // lazyLoad (node, resolve) {
        //   const { level } = node;

        //   // setTimeout(() => {
        //   //   const nodes = Array.from({ length: level + 1 })
        //   //     .map(item => ({
        //   //       value: Date.now(),
        //   //       label: `选项${Date.now()}`,
        //   //       leaf: level >= 6
        //   //     }));
        //   //   // 通过调用resolve将子节点数据返回，通知组件数据加载完成
        //   //   resolve(nodes);
        //   // }, 1000);
        // }
      },
      searchImgName:'',
      previewImg:'',
    }
  },
  computed: {
    disabledDeleteGroup() {
      return this.selectCatgory == 0
    },
    disabledBtnCropper() {
      if (this.multiple) {
        return this.selected.length !== 1
      } else {
        return !this.selected
      }
    },
    disabledBtnEdit() {
      return this.multiple ? this.selected.length == 0 : !this.selected
    },
    disabledBtnDelete() {
      return this.multiple ? this.selected.length == 0 : !this.selected
    },
    disabledBtnDownload() {
      return this.multiple ? this.selected.length == 0 : !this.selected
    },
    disabledBtnCancel() {
      return this.multiple ? this.selected.length == 0 : !this.selected
    },
    disabledBtn() {
      return this.multiple ? this.selected.length == 0 : !this.selected
    }
  },
  created() {},
  mounted() {
    this.nextPage()
    // this.getImageAllCatgory()
  },
  methods: {
    isActive({ image_id, url }) {
      if (this.multiple) {
        return isArray(this.selected) ? this.selected.findIndex((item) => item.url == url) : false
      } else {
        // return this.selected ? this.selected.image_id == image_id : false
        if (this.selected) {
          const handleRegExp = (str) => {
            const regExp = /^(http|https):\/\/(.*)/g
            const [p1, p2, p3] = regExp.exec(str)
            return p3
          }
          if (isObject(this.selected)) {
            if (this.selected.url) {
              return handleRegExp(this.selected.url) == handleRegExp(url)
            }
            return false
          } else {
            return handleRegExp(this.selected) == handleRegExp(url)
          }
        } else {
          return false
        }
      }
    },
    async loadNode(node, resolve) {
      // console.log('loadNode',node,node.level)
      if (node.level === 0) {
        resolve([{
          image_cat_id: 0, 
          image_cat_name: '全部图片',
        }])
      }
      else{
        const { list } = await this.$api.picker.getImageAllCatgory({ image_cat_id: node.data.image_cat_id })
        // console.log('list',list)
        resolve(this.sortGroupList(list));
        return 
      }
      // if (node.level > 1) return resolve([]);
      // else{
      //   setTimeout(() => {
      //     const data = [
      //       {
      //         image_cat_id: Date.now(),
      //         image_cat_name: '没有下级'+(node.level+1),
      //         leaf: true
      //       }, 
      //       {
      //         image_cat_name: '有下级'+(node.level+1)
      //       }
      //     ];

      //     resolve(data);
      //   }, 500);
      // }
    },
    sortGroupList(list){
      // return list.reverse();
      return list.sort((l,r)=>l.sort-r.sort)
    },
    onAddGroup() {
      const { groupForm } = this.$options.data()
      let node = this.$refs.treeRef.getCurrentNode();
      // console.log("node",node)
      if(node.image_cat_id){
        groupForm.parent_id = node.image_cat_id;
        groupForm.parent_name = node.image_cat_name;
      }
      this.groupForm = groupForm
      this.groupDialog = true
    },
    onEditGroup({ image_cat_id, image_cat_name,sort=0,parent_id=0, },{parent:{data:parentData}}) {
      // console.log('onEditGroup',parentData)
      this.groupForm = {
        groupId: image_cat_id,
        groupName: image_cat_name,
        sort,
        parent_id,
        parent_name:parentData.image_cat_name,
      }
      this.groupDialog = true
    },
    async onDeleteGroup({ image_cat_id, image_cat_name },node) {
      try {
        await this.$confirm(`确认删除分组【${image_cat_name}】？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        })
        await this.$api.picker.deleteImageGroup(image_cat_id)
        // this.getImageAllCatgory()
        this.$refs.treeRef.remove(node)
        // this.$refs.treeRef.setCurrentKey(0)
        this.handleClickCatgory({image_cat_id:0})
        this.refresh(true)
      } catch (e) {
        console.log(e)
      }
    },
    async onGroupFormSubmit() {
      const { groupId, groupName,sort,parent_id } = this.groupForm
      let newData = null
      let subData = {
        image_cat_name: groupName,
        // parent_id: 0,
        parent_id,
        sort,
      }
      if (groupId) {
        // 编辑
        subData.image_cat_id = groupId
        newData = await this.$api.picker.addImageCatgory(subData)
        // this.$set(node,'data',subData)
        let node = this.$refs.treeRef.getNode(groupId)
        console.log('currNode',node,parent_id)
        const { list } = await this.$api.picker.getImageAllCatgory({ image_cat_id:parent_id })
        // console.log('list',list)
        this.$refs.treeRef.updateKeyChildren(parent_id,this.sortGroupList(list))
        // let parentNode = node.parent
        // this.$refs.treeRef.remove(node)
        // this.$refs.treeRef.append(newData,parent_id)
      } else {
        // 添加
        newData = await this.$api.picker.addImageCatgory(subData)
        // subData.image_cat_id = Date.now();
        let node = this.$refs.treeRef.getCurrentNode();
        this.$refs.treeRef.append(newData,node)
      }
      console.log('addImageCatgory',newData)
      this.groupDialog = false
      // this.getImageAllCatgory()
    },
    onMoveGroup() {
      this.editDialog = true
      this.editForm.groupId = ''
    },
    async onEditFormSubmit() {
      this.$refs.editForm.validate(async (valid)=>{
        if(valid){
          const { groupId } = this.editForm
          // console.log('groupId',groupId.pop())
          // this.$refs['editDialogRef'].resetForm()
          let image_id
          if (isArray(this.selected)) {
            image_id = this.selected.map(({ image_id }) => image_id)
          } else {
            image_id = this.selected.image_id
          }
          await this.$api.picker.moveImageGroup({
            image_cat_id: groupId.pop(),
            // company_id => '企业id必填,必须为整数',
            image_id: image_id.toString()
          })
          // this.$refs['editForm'].resetForm()
          this.editDialog = false
          this.refresh(true)
          this.handleCancelAll();
        }
        else{
          console.log('error submit!!');
          return false;
        }
      })
    },

    handleEdit() {
      const { multiple, selected } = this
      this.editFormList[1].disabled = false
      if (multiple && selected.length == 1) {
        this.editForm.name = selected[0].image_name
      } else if (!multiple && selected) {
        this.editForm.name = selected.image_name
      } else {
        this.editFormList[1].disabled = true
      }
      this.editDialog = true
    },
    handleCropper() {
      const { selected, multiple } = this
      this.option.img = multiple ? selected[0].url : selected.url
      this.cropperDialogShow = true
    },
    async fetch({ page_no, page_size }) {
      let params = {
        type: 'image',
        page: page_no,
        pageSize: page_size,
        image_name:this.searchImgName,
      }
      if (this.selectCatgory != '0') {
        params = {
          ...params,
          image_cat_id: this.selectCatgory,
        }
      }
      const { list, total_count } = await this.$api.picker.getImageList(params)
      this.list = list
      return { count: total_count }
    },
    async getImageAllCatgory() {
      const { list } = await this.$api.picker.getImageAllCatgory({ image_cat_id: 0 })
      // this.catgoryList = [{ image_cat_id: -1, image_cat_name: '全部图片' }, ...list.reverse()]
      this.catgoryList = [
        {
          image_cat_id: 0, 
          image_cat_name: '全部图片',
          children:[
            // ...list.reverse()
          ]
        }
      ]
      this.editFormList[0].options = this.catgoryList.map((item) => {
        return {
          title: item.image_cat_name,
          value: item.image_cat_id
        }
      })
    },

    handleClickCatgory({ image_cat_id }) {
      this.$refs.treeRef.setCurrentKey(image_cat_id)
      this.selectCatgory = image_cat_id
      this.refresh(true)
    },
    handleClickItem(item) {
      const { image_id, url } = item
      const _item = {
        image_id,
        url
      }
      if (this.multiple) {
        const fdx = this.selected.findIndex((s) => s.image_id == item.image_id)
        if (fdx > -1) {
          this.selected.splice(fdx, 1)
        } else {
          // 默认最多可选20
          const { num = 20 } = this.value
          if (this.selected.length < num) {
            this.selected.push(_item)
          } else {
            this.$message.error(`最多选择${num}张图片`)
            return
          }
        }
      } else {
        this.selected = _item
      }
      this.updateVal(this.selected)
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg'
      const isPNG = file.type === 'image/png'
      const isGIF = file.type === 'image/gif'
      const isLt2M = file.size / 1024 / 1024 < 5
      if (!isJPG && !isPNG && !isGIF) {
        this.$message.error('上传图片只能是 JPG 或者 PNG 格式!')
        return
      }
      if (!isLt2M) {
        this.$message.error('上传图片大小不能超过 5MB!')
        return
      }
      this.localpostData.fname = file.name
    },
    async handleAvatarSuccess(res, file) {
      const uploadParams = {
        image_cat_id: this.selectCatgory, //图片分类必填,必须为整数
        image_name: file.name, //图片名称必填,不能超过50个字符
        image_url: res.key, //图片链接必填
        image_type: file.raw.type, //图片分类长度不能超过20个字符
        storage: 'image' //图片id必填
      }
      await this.$api.qiniu.uploadQiniuPic(uploadParams)
      this.$message.success('上传成功')
      this.refresh(true)
    },
    // 自定义上传
    handleUpload: function (e) {
      const upload = new UploadUtil()
      // 上传
      upload
        .uploadImg(e.file, e.file.name)
        .then(
          (res) => e.onSuccess(res),
          (err) => e.onError(err)
        )
        .catch((err) => e.onError(err))
    },
    // 上传错误回调
    uploadError: function (e) {
      console.error(e)
    },
    async handleCopy(url) {
      await this.$copyText(url)
      this.$notify.success({
        message: '链接复制成功',
        showClose: true
      })
    },
    removeItem(item, index) {
      this.$confirm('确定删除此图片吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteImage({ image_id: item.image_id }).then((response) => {
            this.refresh(true)
            this.$message({
              message: '删除成功',
              type: 'success',
              duration: 5 * 1000
            })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    handleCancelAll() {
      const { multiple } = this
      this.selected = multiple ? [] : null
    },
    handleCropperAction(action) {
      switch (action) {
        case 'minus':
          this.$refs.cropper.changeScale(-2)
          break
        case 'plus':
          this.$refs.cropper.changeScale(2)
          break
        case 'rotateRight':
          this.$refs.cropper.rotateRight()
          break
        case 'rotateLeft':
          this.$refs.cropper.rotateLeft()
          break
      }
    },
    handlePreview(item){
      console.log('handlePreview',item)
      this.previewImg = item.url;
      this.$refs.previewImg.showViewer = true
    },
  }
}
</script>
